package com.tjetc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tjetc.common.Result;
import com.tjetc.entity.Admin;
import com.tjetc.entity.Major;
import com.tjetc.entity.User;
import com.tjetc.service.IMajorService;
import com.tjetc.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @Autowired
    private IMajorService majorService;

    @RequestMapping("/getInfo")
    public Result<?> getInfo(String phone){
        QueryWrapper<User> qw=new QueryWrapper<User>();
        qw.eq("phone",phone);
        User user=userService.getOne(qw);
        user.setMajor(majorService.getById(user.getMajorId()));
        return Result.success(user,"查询个人信息");
    }


    @RequestMapping("/update")
    public Result<?> update(User user, MultipartFile photo, String[] paths){
        System.out.println("user = [" + user + "],  photo = [" + photo + "], paths = [" + paths + "]");


        boolean i=userService.updates(user,photo,paths);
        if (i){
            return Result.success("修改成功");
        }else{
            return Result.fail("修改失败");
        }
    }

}
